#include <iostream>
#include <vector>

using namespace std;
class Solution
{
public:
    int minDeletionSize(vector<string> &strs)
    {
        int row = strs.size(), col = strs[0].size();
        int ans = 0;
        for (size_t i = 0; i < row; i++)
        {
            for (size_t j = 1; j < col; j++)
            {
                // 注意比较的是列而不是行
                if (strs[j - 1][i] > strs[j][i])
                {
                    ans++;
                    break;
                }
            }
        }

        return ans;
    }
    int minDeletionSize_2(vector<string> &strs)
    {
        int n = strs[0].size(), ans = 0;
        for (int i = 0; i < n; i++)
        {
            int last = -1, cnt = 0;
            for (auto &j : strs)
            {
                if (last > j[i])
                {
                    cnt = 1;
                    break;
                }
                last = j[i];
            }
            ans += cnt;
        }
        return ans;
    }
};
int main()
{
    Solution s;
    vector<string> strs = {"cba", "daf", "ghi"};
    cout << s.minDeletionSize(strs) << endl;
    return 0;
}